Skip to content

fix(stdio): enforce the response bound the gateway declares - #486

Merged
imran-siddique merged 1 commit into
mainfrom
fix/stdio-response-limit
Aug 9, 2026
Merged

fix(stdio): enforce the response bound the gateway declares#486
imran-siddique merged 1 commit into
mainfrom
fix/stdio-response-limit

Conversation

@imran-siddique

Copy link
Copy Markdown
Contributor

Follow-up to #485.

MAX_RESPONSE_BYTES was unreachable. create_subprocess_exec was called without a limit=, so the child's stdout stream kept asyncio's 64 KiB default, and readline() raises a bare ValueError past that. The call sits inside async with self._lock with no try, so it escaped uncaught.

The practical effect: an ordinary 200 KiB tool response, a file read or a search result, failed as an unhandled exception inside the enclave, and the 8 MB bound the gateway advertises never applied.

Two changes:

  • Pass the declared bound as the stream limit, so the number in the source is the number enforced.
  • Turn the over-limit case into an UpstreamUnavailable refusal that names the reason, consistent with how every other framing failure on this path is reported. The session is closed, matching the desync and mismatched-id decisions.

Two tests. One sends a 200 KiB response and asserts it round-trips, which fails on the pre-fix code with a ValueError. The other monkeypatches the bound down so the refusal path can be exercised without generating 8 MB.

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

🤖 Generated with Claude Code

asyncio gives a subprocess stdout stream a 64 KiB limit unless told
otherwise, so readline() raised a bare ValueError well before
MAX_RESPONSE_BYTES was ever consulted. An ordinary 200 KiB tool response
failed as an unhandled exception inside the enclave, and the 8 MB bound
was unreachable.

Pass the declared bound as the stream limit and turn the over-limit case
into an UpstreamUnavailable refusal that names the reason, matching how
every other framing failure on this path is reported.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@imran-siddique
imran-siddique merged commit d7a5217 into main Aug 9, 2026
12 checks passed
@imran-siddique
imran-siddique deleted the fix/stdio-response-limit branch August 9, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant